package visiopuce.ui.providers;

import java.util.Date;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;

import visiopuce.objets.Cotation;

public class CotationDateEditingSupport extends EditingSupport {

	private final TableViewer viewer;
	private final DateCellEditor editor;

	public CotationDateEditingSupport(TableViewer viewer, int idPersonne) {
		super(viewer);
		this.viewer = viewer;
		this.editor = new DateCellEditor(viewer.getTable());
	
	}

	@Override
	protected CellEditor getCellEditor(Object element) {
		return editor;
	}

	@Override
	protected boolean canEdit(Object element) {
		return true;
	}

	@Override
	protected Object getValue(Object element) {
		return ((Cotation) element).getDate();
	}

	@Override
	protected void setValue(Object element, Object value) {
		if (element instanceof Cotation)  {
			((Cotation) element).setDate((Date) editor.doGetValue());	
		}
		viewer.update(element, null);
	}

}